package huxibianjie.com.lbscandroid.receiver;

import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import org.greenrobot.eventbus.EventBus;

import huxibianjie.com.lbscandroid.event.ClickEvent;

public class NetBroadcastReceiver extends BroadcastReceiver {

    @SuppressLint("UnsafeProtectedBroadcastReceiver")
    @Override
    public void onReceive(Context context, Intent intent) {
        ConnectivityManager connectMgr = (ConnectivityManager) context.getSystemService(context.CONNECTIVITY_SERVICE);
        NetworkInfo mobNetInfo = connectMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        NetworkInfo wifiNetInfo = connectMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        EventBus.getDefault().post(new ClickEvent(ClickEvent.Type.NET_WORK_STATE, null,
                mobNetInfo != null && mobNetInfo.isConnected() || wifiNetInfo != null && wifiNetInfo.isConnected()));
    }
}